package tech.lq0.dreamaticdelight.item.food.shirako;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import tech.lq0.dreamaticvoyage.capability.chaos.ChaosHelper;
import tech.lq0.dreamaticvoyage.tools.Livers;
import tech.lq0.dreamaticvoyage.tools.TooltipTool;
import vectorwing.farmersdelight.common.item.ConsumableItem;

import java.util.List;

public class MomoSandwich extends ConsumableItem {

    private static final FoodProperties FOOD = (new FoodProperties.Builder()).saturationMod(0.4F).nutrition(6)
            .effect(() -> new MobEffectInstance(MobEffects.LEVITATION, 40, 0), 1.0F)
            .build();

    public MomoSandwich() {
        super(new Properties().food(FOOD), true);
    }

    @Override
    public void appendHoverText(ItemStack pStack, @Nullable Level pLevel, List<Component> pTooltipComponents, TooltipFlag pIsAdvanced) {
        pTooltipComponents.add(Component.translatable("des.dreamaticdelight.momo_sandwich").withStyle(ChatFormatting.GRAY));
        super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced);
        TooltipTool.addChaosInfo(pTooltipComponents, 0);
        TooltipTool.addLiverInfo(pTooltipComponents, Livers.SHIRAKO);
    }

    @Override
    public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity consumer) {
        if (consumer instanceof Player player) {
            if (!level.isClientSide) {
                int random = (int) (Math.random() * 99.0 + 1.0);
                if (random > 90) {
                    player.setSecondsOnFire(10);
                    player.displayClientMessage(Component.translatable("des.dreamaticvoyage.momo_daifuku.fire").withStyle(ChatFormatting.RED), true);
                }

                ChaosHelper.resetChaos(player);
            }
        }

        return super.finishUsingItem(stack, level, consumer);
    }
}
